﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace _1_14
{
    class Product
    {
        readonly string name;
        public string Name { get { return name; } }

        readonly decimal? price;
        public decimal? Price { get { return price; } }

        public Product(string name, decimal? price)
        {
            this.name = name;
            this.price = price;
        }

        public static List<Product> GetSampleProducts()
        {
            return new List<Product>
            {
                new Product(name: "West Side Story", price: 9.99m),
                new Product(name: "Assassins", price: 14.99m),
                new Product(name: "Frogs", price: 13.99m),
                new Product(name: "Sweeny", price: null)
            };
        }

        public override string ToString()
        {
            return string.Format("{0}: {1}", name, price);
        }
    }

    class Program
    {
        static void Main_()
        {
            List<Product> products = Product.GetSampleProducts();
            foreach (Product product in products.Where(p => p.Price == null))
            {
                Console.WriteLine(product);
            }
            products.FindAll(delegate (Product p) { return p.Price == null; })
                .ForEach(Console.WriteLine);
        }
    }
}
//Nullable<T>结构。可以将值类型设为空